<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button id="btn">按钮</button>
<P id="pTime"></P>
<script>
    //第一个参数是方法，第二个是延迟的时间
    var myTime=setInterval(function () {
        getTime();
    },1000);
    function  getTime() {
        var d=new Date();
        var t=d.toLocaleTimeString();
        document.getElementById("pTime").innerHTML=t;
    }
    //停止时间
    function stopTime(){
        clearInterval(myTime);
    }


</script>
</body>
</html>